<?php
        function a($str,$link,$table){

            $sql = "select * from `menber` where `$table`='$str'";

            mysqli_query($link,$sql);
            $rows = mysqli_affected_rows($link);
            return $rows;
        }

    if(!empty($_SERVER['HTTP_X_REQUESTED_WITH'])){

        /*从昵称提交过来的ajax*/
        if(!empty($_GET['name'])){

            /*获取$_GET数组中值为4的键名*/
            $table = array_keys($_GET,4);
            $table = $table[0];

            /*把提交过来的昵称用变量接住*/
            $str = $_POST['str'];

            /*调用查询语句，$str：用户提交的昵称，$link：链接数据库，$table：要查询的字段名，函数返回影响行数$rows*/
            $rows = a($str,$link,$table);

            if($rows>0){
                echo 1;
            }else{
                echo 0;
            }
        }
            /*从邮箱提交过来的ajax*/
         if(!empty($_GET['username'])){
            $table = array_keys($_GET,5);
            $table = $table[0];

            $str = $_POST['str1'];

            $rows1 = a($str,$link,$table);
            if($rows1>0){
                echo 1;
            }else{
                echo 0;
            }
        }
    }